package com.dtzhejiang.social.supervision.risk.engine.core.task;

import com.dtzhejiang.social.supervision.risk.engine.common.enums.JobEnums;
import lombok.extern.slf4j.Slf4j;
import org.springframework.batch.core.JobParametersBuilder;
import org.springframework.batch.core.job.builder.SimpleJobBuilder;
import org.springframework.batch.core.launch.JobLauncher;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.Map;

/**
 * @Author: Lexus
 * @Date: 2020/12/15 17:38
 */
@Component
@Slf4j
public class TaskEntry {
    private static final String DATE_PARAMETER = "date";
    @Autowired
    private JobLauncher jobLauncher;

    @Autowired
    private Map<String, SimpleJobBuilder> jobBuilderMap;
    
    /**
     * 每隔5秒
     */
    private static final String ANALYSIS_LICENSE_TIME = "*/10 * * * * ?";

    @Scheduled(cron=ANALYSIS_LICENSE_TIME)
    public void entry() {
        try {
            jobLauncher.run(jobBuilderMap.get(JobEnums.LICENSE.getCode()).build(), new JobParametersBuilder().addDate(DATE_PARAMETER, new Date()).toJobParameters());
        }catch (Exception e){
            log.error("license job run failed;", e);
        }
    }
}
